package cn.bonoon.services;

import java.util.List;

import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletResponse;

import org.batatasframework.common.ParameterReader;
import org.batatasframework.immadiate.ImmadiatePlanDefinition;
import org.batatasframework.immadiate.ImmadiateScheduleHandler;
import org.batatasframework.immadiate.ImmediateTaskHandler;
import org.batatasframework.immadiate.ImmediateTaskInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.ui.Model;

import cn.bonoon.core.ImmediateTaskService;
import cn.bonoon.entities.ImmediateTaskEntity;
import cn.bonoon.kernel.io.FileManager;
import cn.bonoon.kernel.support.IOperator;
import cn.bonoon.kernel.support.services.ServiceSupport;

@Service
@Transactional(readOnly = true)
public class ImmediateTaskServiceImpl extends ServiceSupport implements ImmediateTaskService {
	@Autowired
	private ImmadiateScheduleHandler immadiateScheduleHandler;
	private @Autowired FileManager fileManager;
	@Override
	public ImmediateTaskInfo myTask(IOperator user,
			String catalog, List<ImmediateTaskInfo> tasks) {
		return immadiateScheduleHandler.myTask(entityManager, user, tasks);
	}

	@Override
	public ImmediateTaskHandler<? extends ImmediateTaskEntity> findTaskHandler(
			String catalog, String key) {
		// TODO Auto-generated method stub
		return immadiateScheduleHandler.findTaskHandler(catalog, key);
	}

	@Override
	public ImmadiatePlanDefinition findDefinition(String catalog, String key) {
		// TODO Auto-generated method stub
		return immadiateScheduleHandler.findDefinition(catalog, key);
	}

//	@Override
//	public ImmediateTaskHandler<? extends ImmediateTaskEntity> __findTaskHandler(
//			String key) {
//		// TODO Auto-generated method stub
//		return null;
//	}

	@Override
	@Transactional
	public void deleteMaterial(String catalog, String key, IOperator user, Long taskid, Long id) {
		immadiateScheduleHandler.deleteMaterial(catalog, key, entityManager, user, taskid, id);
		
		
	}

	@Override
	@Transactional
	public void update(String catalog, String key, IOperator user, ParameterReader parameter)
			throws Exception {
		// TODO Auto-generated method stub
		immadiateScheduleHandler.update(catalog, key, entityManager, fileManager, user, parameter);
		
	}

	@Override
	@Transactional
	public void accepted(IOperator operator, ImmediateTaskEntity task) {
		// TODO Auto-generated method stub
		immadiateScheduleHandler.accepted(entityManager, operator, task);
	}

	@Override
	public ImmediateTaskEntity loadToShow(ImmadiatePlanDefinition def,
			IOperator user, ParameterReader parameter, Model model) {
		
		return immadiateScheduleHandler.loadToShow(def, entityManager, user, parameter, model);
	}
	
	@Override
	public void export(IOperator user, String catalog, String key, ParameterReader parameter, HttpServletResponse response,ServletContext servletContext) {
		immadiateScheduleHandler.export(user, catalog, key, parameter, response, servletContext, entityManager);
	}
}
